# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=certifi
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2018.4.16
pkgrel=1
pkgdesc="Python package for providing Mozilla's CA Bundle (mingw-w64)"
url='https://pypi.python.org/pypi/certifi'
license=('GPL')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
            )
source=("https://pypi.io/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7')

prepare() {
  cd ${srcdir}
  cp -r ${_realname}-${pkgver} build-python2
  cp -r ${_realname}-${pkgver} build-python3
  
  cd build-python2
  sed -i '1s|python$|python2|' certifi/core.py
}

package_python3-certifi() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")
  cd ${srcdir}/build-python3
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_python2-certifi() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")
  cd ${srcdir}/build-python2
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-certifi() {
  package_python2-certifi
}

package_mingw-w64-i686-python3-certifi() {
  package_python3-certifi
}

package_mingw-w64-x86_64-python2-certifi() {
  package_python2-certifi
}

package_mingw-w64-x86_64-python3-certifi() {
  package_python3-certifi
}
